﻿#include "FloatingRock.h"
#include "../../../Shared/Functions/Functions.h"
#include "../../MirEnvir/Envir.h"
#include "../../../Shared/ServerPackets.h"
#include "../../../Shared/Data/Stat.h"
#include "../DelayedAction.h"

using namespace Server::MirDatabase;
using namespace Server::MirEnvir;
namespace S = ServerPackets;

namespace Server::MirObjects::Monsters
{

    bool FloatingRock::getCanMove() const
    {
        return false;
    }

    unsigned char FloatingRock::getAttackRange() const
    {
        return 7;
    }

    FloatingRock::FloatingRock(MonsterInfo *info) : MonsterObject(info)
    {
    }

    bool FloatingRock::Walk(MirDirection dir)
    {
        return false;
    }

    bool FloatingRock::InAttackRange()
    {
        return getCurrentMap() == getTarget()->getCurrentMap() && Functions::InRange(getCurrentLocation(), getTarget()->getCurrentLocation(), getAttackRange());
    }

    void FloatingRock::Attack()
    {

        if (!getTarget()->IsAttackTarget(this))
        {
            setTarget(nullptr);
            return;
        }

        ShockTime = 0;
        setDirection(Functions::DirectionFromPoint(getCurrentLocation(), getTarget()->getCurrentLocation()));
        bool ranged = getCurrentLocation() == getTarget()->getCurrentLocation() || !Functions::InRange(getCurrentLocation(), getTarget()->getCurrentLocation(), 1);

        ActionTime = getEnvir()->getTime() + 300;
        AttackTime = getEnvir()->getTime() + AttackSpeed;

        S::ObjectRangeAttack *tempVar = new S::ObjectRangeAttack();
        tempVar->ObjectID = ObjectID;
        tempVar->Direction = getDirection();
        tempVar->Location = getCurrentLocation();
        tempVar->TargetID = getTarget()->ObjectID;
        Broadcast(tempVar);

        int damage = GetAttackPower(Stats[Stat::MinMC], Stats[Stat::MaxMC]);
        if (damage == 0)
        {
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar' statement was not added since tempVar was passed to a method or constructor. Handle memory management manually.
            return;
        }
        DelayedAction *action = new DelayedAction(DelayedType::RangeDamage, getEnvir()->getTime() + 1000, {getTarget(), damage, DefenceType::MAC});
        ActionList.push_back(action);

        if (getTarget()->Dead)
        {
            FindTarget();
        }

//C# TO C++ CONVERTER TODO TASK: A 'delete action' statement was not added since action was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar' statement was not added since tempVar was passed to a method or constructor. Handle memory management manually.
    }

    void FloatingRock::ProcessRoam()
    {
    }
}
